package com.nondo.rdp.stock.repository;

import com.nondo.rdp.core.common.StatusConstant;
import com.nondo.rdp.stock.domain.SimulateLog;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.Date;
import java.util.List;
import java.util.Optional;

public interface SimulateLogRepository extends JpaRepository<SimulateLog, Long>, JpaSpecificationExecutor<SimulateLog> {
    @Query("select a from SimulateLog a where a.id=:id and delFlag = '" + StatusConstant.DEL_FLAG_NORMAL + "'")
    Optional<SimulateLog> findOne(@Param("id") int id);

    @Modifying
    @Query("update SimulateLog set delFlag='" + StatusConstant.DEL_FLAG_DELETE + "' where id = ?1")
    void deleteById(Long id);

    SimulateLog save(SimulateLog simulateLog);

    List<SimulateLog> findAllByCodeAndCreateTimeAfter(String code, Date createTime);
}
